<?php

class User_data extends Data {
	private $alias = 'admin-yueshihui-com';
	private $tb = 'user';
	
	private $cols = array('uid', 'username', 'password', 'realname', 'is_supper', 'remark');

	/**
	 * 创建用户
	 * @param unknown_type $cols
	 */
	public function createUser($cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		if($db->insert($this->tb, $cols)) return $db->lastInsertId();
		else return false;
	}

	/**
	 * 删除用户
	 * @param unknown_type $params
	 */
	public function deleteUser($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->delete($this->tb, $params);
	}

	/**
	 * 更新用户信息
	 * @param unknown_type $params
	 * @param unknown_type $cols
	 */
	public function editUser($params, $cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->update($this->tb, $cols, $params);
	}

	/**
	 * 单个用户信息
	 * @param unknown_type $params
	 */
	public function userInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;

		$user = $db->one($this->tb, $this->cols, $params);
		return $user;
	}

	/**
	 * 批量获取用户信息
	 * @param unknown_type $params
	 */
	public function usersInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;

		$user = $db->select($this->tb, $this->cols, $params);
		return $user;
	}
	
	/**
	 * 分页获取用户信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function page($page, $size, $params, $orderBy = '`uid` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb, $this->cols, $params, $orderBy, $page, $size);
	}
	
	/**
	 * 获取用户记录数
	 * @param unknown_type $params
	 */
	public function count($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb, $params);
	}
}